import os 
import django 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wechat.settings")   #这里的pga_lord就是你的项目名称
django.setup()

from sogou.models import *
from django.db.models import Q

if __name__ == "__main__":
    import datetime
    dt = datetime.date.today()

    w = Wechat.objects.create(title="t",link="http://www.baidu.com",abstract="....",date=dt) #创建一个wechat类的实例
    w.save()#写入这实例到数据库
    print(len(Wechat.objects.all()))

    ret = Wechat.objects.filter(Q(title="t") & Q(link="http://www.baidu.com")) # select * from sogou_wechat where title='t' and linke='http://www.baidu.com'

    for r in ret:
        print("---",r)

    print(type(ret[0]))
    w = ret[0]
    w.title = "update...."
    w.save()

    for row in Wechat.objects.all():
        print(row)

    Wechat.objects.filter(Q(title="t") & Q(link="http://www.baidu.com")).delete()
    print(len(Wechat.objects.all()))
    Wechat.objects.all().delete()


    